package models.ru.paralainer.chat.server.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import play.db.jpa.Model;

/**
 * User: stalov
 * Date: 22.05.12
 * Time: 10:02
 */
@Entity
@Table(name = "Message")
@NamedQueries(
        {
                @NamedQuery(
                        name = "Message.findOlder",
                        query = "select o from Message o where o.date > :date order by o.date asc "
                ),
                @NamedQuery(
                        name = "Message.findOlderByMessageId",
                        query = "select o from Message o, Message o1 where o.date > o1.date and o1.id = :id order by o.date asc"
                )
        }
)

public class Message extends Model {

    protected String text;

    @Temporal(
            TemporalType.TIMESTAMP
    )
    protected Date date;

    @ManyToOne(
            fetch = FetchType.EAGER
    )
    protected User user;


    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
